package com.think.admin.oauth.exception;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.think.common.utils.ResultUtil;
import org.springframework.http.HttpStatus;

import java.io.IOException;

/**
 * <p>
 * 序列化
 * </p>
 *
 * @author: xwj
 * @data: 2019-05-07
 */
public class CustomOauth2ExceptionSerializer extends StdSerializer<CustomOauth2Exception> {
    public CustomOauth2ExceptionSerializer() {
        super(CustomOauth2Exception.class);
    }

    @Override
    public void serialize(CustomOauth2Exception e, JsonGenerator gen, SerializerProvider provider)
            throws IOException {
        gen.writeObject(new ResultUtil(HttpStatus.resolve(e.getHttpErrorCode()), e.getOAuth2ErrorCode()));
    }
}
